//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Query Application Block
//===============================================================================

using System;
using System.Data;
using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Unity;
using EntLibContrib.Query.Configuration.Unity;
using EntLibContrib.Query.Parameters;

namespace EntLibContrib.Query.Configuration
{
	/// <summary>
	/// Type to hold the elements of a single query parameter
	/// </summary>
	[Assembler(typeof(DataParameterAssembler))]
	[ContainerPolicyCreator(typeof(DataParameterPolicyCreator))]
	public class DataParameterData : ParameterData
	{
		#region Fields
		private const string dbTypeProperty = "dbType";
		private const string directionProperty = "direction";
		#endregion

		#region Properties
		/// <summary>
		/// Gets or sets the type of the parameter.
		/// </summary>
		/// <value>The type of the parameter.</value>
		[ConfigurationProperty(dbTypeProperty, IsRequired = true)]
		public DbType DbType
		{
			get { return (DbType)base[dbTypeProperty]; }
			set { base[dbTypeProperty] = value; }
		}

		/// <summary>
		/// Gets or sets the parameter direction.
		/// </summary>
		/// <value>The parameter direction.</value>
		/// <remarks>the directions are In or Out</remarks>
		[ConfigurationProperty(directionProperty, IsRequired = true)]
		public ParameterDirection Direction
		{
			get { return (ParameterDirection)base[directionProperty]; }
			set { base[directionProperty] = value; }
		}
		#endregion

		#region Construction
		/// <summary>
		/// Initializes a new instance of the <see cref="DataParameterData"/> class.
		/// </summary>
		public DataParameterData()
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="DataParameterData"/> class.
		/// </summary>
		/// <param name="name">The parameter name.</param>
		/// <param name="dbType">Type of the parameter.</param>
		/// <param name="direction">The direction of the parameter relative to the data source.</param>
		public DataParameterData(
			string name,
			DbType dbType,
			ParameterDirection direction
			)
			: base(name, typeof(DataParameter))
		{
			this.DbType = dbType;
			this.Direction = direction;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="DataParameterData"/> class.
		/// </summary>
		/// <param name="name">The parameter name.</param>
		/// <param name="type">The type.</param>
		/// <param name="dbType">Type of the parameter.</param>
		/// <param name="direction">The direction of the parameter relative to the data source.</param>
		public DataParameterData(
			string name,
			Type type,
			DbType dbType,
			ParameterDirection direction
			)
			: base(name, type)
		{
			this.DbType = dbType;
			this.Direction = direction;
		}
		#endregion
	}
}
